//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.aidong.web.controller.sys;

import com.aidong.dao.base.Pagination;
import com.aidong.dao.wills.DicAdmAreaCodeDao;
import com.aidong.dao.wills.SysMessageDao;
import com.aidong.dao.wills.SysMessageReadDao;
import com.aidong.model.wills.SysMessage;
import com.aidong.web.controller.BaseController;
import java.util.ArrayList;
import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping({"sysMessageRead"})
public class SysMessageReadController extends BaseController {
    @Resource
    SysMessageDao sysMessageDao;
    @Resource
    SysMessageReadDao sysMessageReadDao;
    @Resource
    DicAdmAreaCodeDao dicAdmAreaCodeDao;

    public SysMessageReadController() {
    }

    @RequestMapping({"list"})
    public ModelAndView list() {
        return new ModelAndView("sys/messageread/list");
    }

    @RequestMapping({"_list"})
    public ModelAndView _list(@RequestParam(value = "title",required = false) String title, @RequestParam(value = "status",required = false) Integer status, @RequestParam(value = "pageNo",required = false) String pageNo, @RequestParam(value = "totalCount",required = false) String totalCount) {
        Pagination pg = new Pagination(1, 20);
        pg.setPage(this.parseInt(pageNo), this.parseInt(totalCount));
        ArrayList recvList = new ArrayList();
        recvList.add("0-all");
        recvList.add("1-" + this.getLoginUserCode());
        recvList.add("3-" + this.getLoginShopCode());
        this.sysMessageDao.queryReadPageList(pg, this.getLoginUserCode(), recvList);
        ModelAndView mv = new ModelAndView("sys/messageread/_list");
        mv.addObject("list", pg.getResultList());
        mv.addObject("pg", pg);
        return mv;
    }

    @RequestMapping({"view"})
    public ModelAndView view(@RequestParam("msgId") int msgId) {
        SysMessage message = (SysMessage)this.sysMessageDao.getById(Integer.valueOf(msgId));
        if(message == null) {
            return this.showAlert("没有这个通知");
        } else {
            ArrayList picList = null;
            if(!this.chkNull(message.getPicUrls())) {
                picList = new ArrayList();
                String[] mv = message.getPicUrls().split(",");
                String[] arr$ = mv;
                int len$ = mv.length;

                for(int i$ = 0; i$ < len$; ++i$) {
                    String s = arr$[i$];
                    picList.add(s);
                }
            }

            message.setContent(message.getContent().replaceAll("\n", "<br>"));
            if(!this.sysMessageReadDao.chkRead(msgId, this.getLoginUserCode())) {
                try {
                    this.sysMessageReadDao.addRead(msgId, this.getLoginUserCode());
                    this.addUserLog("读取通知", "编号:" + message.getMsgId() + ",标题:" + message.getTitle());
                    this.userSession.updateUserMsgNum();
                } catch (Exception var9) {
                    this.log.error("add messageread", var9);
                }
            }

            ModelAndView var10 = new ModelAndView("sys/messageread/view");
            var10.addObject("message", message);
            var10.addObject("picList", picList);
            var10.addObject("_picPath", this.getSetting("pic.path"));
            return var10;
        }
    }

    @RequestMapping({"_del"})
    @ResponseBody
    public String _del(@RequestParam("msgId") int msgId) {
        SysMessage message = (SysMessage)this.sysMessageDao.getById(Integer.valueOf(msgId));
        if(message == null) {
            return this.getResult(false, "没有这个通知");
        } else {
            try {
                this.sysMessageReadDao.updateDelete(msgId, this.getLoginUserCode());
                this.addUserLog("删除通知", "编号:" + message.getMsgId() + ",标题:" + message.getTitle());
            } catch (Exception var4) {
                this.log.error("del messageread", var4);
                return this.getResult(false, "保存发生错误");
            }

            return this.getResult(true, "删除成功");
        }
    }
}
